<%--
  Created by IntelliJ IDEA.
  User: 闫佳宁
  Date: 2024/1/22
  Time: 9:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%
    String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>
<html>
<head>
    <base href="<%=baseUrl%>">
    <title>编辑会议室信息</title>
    <link rel="stylesheet" href="layui/css/layui.css">
</head>
<body>
<form class="layui-form">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">会议室名称</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="name" placeholder="请输入会议室名称">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">容量</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="capacity" placeholder="请输入会议室容量">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">地点</label>
            <div class="layui-input-inline">
                <input class="layui-input" type="text" name="address" placeholder="请输入会议室地点">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="id" value="${param.id}">
                <button class="layui-btn" lay-submit lay-filter="edit">编辑</button>
            </div>
        </div>
    </form>

    <script src="layui/layui.js"></script>
    <script>

        layui.use(['form'], function () {
            var form = layui.form;
            var $ = layui.$;

            //数据回显  根据ID得到所有信息
            getBoardroom(${param.id});//用EL表达式来获取id的参数


            //获取 指定ID的员工信息
            function getBoardroom(id) {
                $.ajax({
                    url: 'boardroom?action=getById',
                    data: {id: id},
                    type: 'get',
                    dateType: 'json',
                    success(result) {
                        if (result.code === 0) {
                            //数据回显
                            $('input[name="name"]').val(result.data.name);
                            $('input[name="capacity"]').val(result.data.capacity);
                            $('input[name="address"]').val(result.data.address);
                        } else {
                            layer.msg(result.msg, {icon: 5});
                        }
                    },
                    error() {
                        layer.msg('请求失败', {icon: 5});
                    }
                });
            }


            //表单的提交
            form.on('submit(edit)', function (data) {
                $.ajax({
                    url: 'boardroom?action=edit',
                    data: data.field,
                    type: 'post',
                    dateType: 'json',
                    success(result) {
                        if (result.code == 0) {
                            layer.msg('编辑成功', {icon: 6}, function () {
                                parent.layer.closeAll('iframe');

                            })
                        } else {
                            layer.msg(result.msg, {icon: 5})
                        }
                    },
                    error() {
                        layer.msg('请求失败', {icon: 5});
                    }
                });

                //阻止表单自动提交
                return false;
            });
        });
    </script>

</body>
</html>
